package point;

/**
 * 题目判断一个数字是否是两个数的平方和
 * 例子：Input: 5, Output: 1, 2
 * 思路：使用双指针
 */
public class Sqrt {
    public static void main(String[] args) {
        Sqrt sqrt = new Sqrt();
        boolean result = sqrt.findSqrt(5);
        System.out.println(result ? "YES" : "NO");
    }

    public boolean findSqrt(int x) {
        int left = 0; int right = (int) Math.sqrt(x);
        while (left <= right) {
            int sum = left*left + right*right;
            System.out.println(sum);
            if (sum == x) {
                return true;
            } else if (sum > x) {
                right--;
            } else {
                left++;
            }
        }
        return false;
    }
}
